const express = require('express');
const app = express();
import Home from '../containers/Home/index.js';
import React from 'react';
import { renderToString } from 'react-dom/server';
app.use(express.static('public')); //静态资源处理

const HomeContent = renderToString(<Home />);
app.get('/', (req, res) => res.send(

    // 这里是通过renderToString方法将我们的虚拟DOM渲染为了一个字符串返回给客户端。
    // 而我们之前使用的ReactDOM.render()则是将虚拟dom渲染为真实dom，插入一个几点中。
    `
        <!DOCTYPE html>
        <html lang="en">
        <head>
          <meta charset="UTF-8">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <meta http-equiv="X-UA-Compatible" content="ie=edge">
          <title>Document</title>
        </head>
        <body>
          <div id="root">${HomeContent}</div>
          <script src="/index.js"></script>
        </body>
        </html>
    `
))

app.listen(3000, () => console.log('Example app listening on port 3000!'))
